package com.yksj.healthtalk.ui.doctorstation;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alibaba.fastjson.JSONObject;
import com.yksj.healthtalk.net.http.AsyncHttpResponseHandler;
import com.yksj.healthtalk.net.http.HttpRestClient;
import com.yksj.healthtalk.net.http.RequestParams;
import com.yksj.healthtalk.ui.R;
import com.yksj.healthtalk.utils.TimeUtil;
/**
 * 查看取消原因
 * @author Administrator
 *
 */
public class DoctorTalkLookCancleReason extends Fragment implements OnClickListener {

	public TextView titleTextV;
	public RelativeLayout title;
	private View mView;
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		mView = inflater.inflate(R.layout.doctor_talk_cancle_reason, null);
		initView();
		return mView;
	}

	private void initView() {
		mView.findViewById(R.id.title_back).setOnClickListener(this);
		title = (RelativeLayout)mView.findViewById(R.id.title_root);
		TextView titleTextV = (TextView)mView.findViewById(R.id.title_lable);
		titleTextV.setText("取消原因");
	}
	
	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		 Bundle bundle = getArguments();
		 String ORIDERID=bundle.getString("ORIDERID");
		String CUSTOMER_ID= bundle.getString("CUSTOMER_ID");
		String DOCTORID =bundle.getString("DOCTORID");
		initData(ORIDERID,CUSTOMER_ID,DOCTORID);
		
		
	}
	
	/**
	 * Type=findcustomerBackOrder
		DOCTORID 医生id
		CUSTOMER_ID 客户id
		ORDER_ID 订单id
	 */
	private void initData(String ORDER_ID,String CUSTOMER_ID,String DOCTORID) {
		RequestParams params = new RequestParams();
		params.put("DOCTORID", DOCTORID);
		params.put("CUSTOMER_ID",CUSTOMER_ID);
		params.put("ORDER_ID", ORDER_ID);
		params.put("Type", "queryCancelOrderMessage");
		HttpRestClient.doHttpServiceSetServletRJ320(params,new AsyncHttpResponseHandler(getActivity()){
			@Override
			public void onSuccess(String content) {
				if(content.contains("error_message")||"".equals(content))return;
				initDataView(content);
//				DoctorOrderDeatils deatils=DoctorOrderDeatils.parsToEntity(content);
			/*	if(deatils==null){
					onFailure(null);
				}else{
					initDataView(deatils);
				}*/
			};
			
		} );
		
	}

	private void initDataView(String deatils){
		JSONObject json=JSONObject.parseObject(deatils);
		
		TextView mOriderType= (TextView)mView.findViewById(R.id.orider_type);
		mOriderType.setText(json.getString("SERVICE_TYPE_SUB"));
		
		TextView mOriderStartTime= (TextView)mView.findViewById(R.id.start_time);
		String start_time=TimeUtil.getFormatTime(json.getString("SERVICE_START"));
		mOriderStartTime.setText(start_time.substring(0, start_time.length()-3));
		
		TextView mOriderReasonPerson=(TextView) mView.findViewById(R.id.cancle_person);
		mOriderReasonPerson.setText(json.getString("CANCEL_CUSTOMER_ACCOUNTS"));
		
		TextView mOriderEndTime= (TextView)mView.findViewById(R.id.cancle_time);
		String start_T=TimeUtil.getFormatTime(json.getString("CANCEL_TIME"));
		mOriderEndTime.setText(start_T.substring(0, start_T.length()-3));
		
		TextView reasonContent=(TextView) mView.findViewById(R.id.reason_content);
		reasonContent.setText(json.getString("CANCEL_REASON"));
	}
	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.title_back:
			getActivity().onBackPressed();
			break;
		}
		
	}
}
